package com.itheima;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @auther Macrydy
 * @date 2020/7/10 18:30
 */
public class UdpServer {
    public static void main(String[] args) throws Exception {
        //创建通道
        DatagramSocket ds = new DatagramSocket(10101);

        while (true) {
            //创建数据包
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

            //接收数据
            ds.receive(dp);

            System.out.println(new String(dp.getData(),0,dp.getLength()));
        }
//        ds.close();
    }
}
